package com.briup.smartcity.web.controller;

import com.briup.smartcity.aop.Logging;
import com.briup.smartcity.bean.BaseConfig;
import com.briup.smartcity.exception.ServiceException;
import com.briup.smartcity.service.IBaseConfigService;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import com.github.pagehelper.PageInfo;
import com.sun.xml.internal.bind.v2.model.core.ID;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "系统配置管理模块")
@RestController
@RequestMapping("/auth/config")
public class SystemConfigController {
    @Autowired
    private IBaseConfigService service;
    @Logging()
    @ApiOperation(value="查询当前启用的系统配置",notes = "对接口的说明信息")
    @GetMapping("/current/config/yes")
    public Result findYesBaseConfig(){
        List<BaseConfig> list = service.findYesBaseConfig();
        return ResultUtil.success(list);
    }
    @ApiOperation("分页查询配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",dataType = "int")
    })
    @GetMapping("/page/query")
    public Result findAllConfig(Integer pageNum, Integer pageSize){
        PageInfo<Config> pageInfo = service.findAllConfig(pageNum, pageSize);
        return ResultUtil.success(pageInfo);
    }
    @ApiOperation("保存配置信息")
    @PostMapping("/save")
    public Result saveConfig(BaseConfig baseConfig){
        System.out.println("配置对象"+baseConfig);
        service.saveConfig(baseConfig);
        return ResultUtil.success("保存成功");
    }
    @ApiOperation("更新配置基本信息")
    @PutMapping("/update")
    public Result updateConfig(BaseConfig baseConfig){
        service.updateConfig(baseConfig);
        return ResultUtil.success("保存成功");
    }
    @ApiOperation("通过id删除配置信息")
    @DeleteMapping ("/deleteById")
    public Result deleteById(int id){
        service.deleteById(id);
        return ResultUtil.success("删除成功");
    }

    @ApiOperation("更新配置状态")
    @PutMapping ("/update/status")
    public Result updateConfigStatus(Integer id,Integer status){
        service.updateConfigStatus(id,status);
        return ResultUtil.success();
    }
//    public Result updateConfigStatus(int id,int status){
//        service.changeConfigStatus(id,status);
//        return ResultUtil.success();
//    }
}
